echo '准备安装环境……'
echo '更新yum……'
yum update
echo '安装yum-utils……'
yum install -y yum-utils device-mapper-persistent-data lvm2
echo '配置镜像源……'
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
echo '查找docker版本……'
yum list docker-ce --showduplicates | sort -r
read -p "请输入Docker的版本号：（例如：23.0.4-1.el7，直接回车安装最新版）" version
echo '开始安装docker……'
if [ -z $version ] 
then 
    echo '正在安装docker最新版……'
    yum install docker-ce
else
    echo '正在安装docker-ce-'$version
    yum -y install 'docker-ce-'$version
fi
echo '设置docker开机启动……'
systemctl enable docker.service
echo '启动docker……'
systemctl start docker
echo '添加国内镜像源……'
touch /etc/docker/daemon.json
echo '{"registry-mirrors": [
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://cr.console.aliyun.com",
    "https://mirror.ccs.tencentyun.com"
  ]}' > /etc/docker/daemon.json
echo '重载配置文件……'
systemctl daemon-reload
echo '重启docker……'
systemctl restart docker
echo '查看docker状态……'
systemctl status docker
echo '查看docker信息……'
docker info
echo '查看docker版本'
docker -v
echo '开始安装docker-compose v2.2.2 ……'
sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
echo '添加执行权限'
sudo chmod +x /usr/local/bin/docker-compose
echo '创建软连接'
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
echo '查看是否安装成功（docker-compose版本）……'
docker-compose version
echo '安装docker和docker-compose结束……'